﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Broker.View.Comm;
using System.Net.Mail;
using SaleLibrary.Tools;
using System.Windows.Controls;
using log4net;
using BrokerBase.Lib.Client;
using BrokerBase.Lib.Company;

namespace Broker.Mgr
{
    public static class AppGlobal
    {
        private static object syncClientCfgRoot = new object();
        private static ClientConfiguration clientCfg;

        private static IList<SmtpClient> smtpClients;

        private static readonly BaseDataType[] dts = new BaseDataType[]
            {
                new BaseDataType("int","整数"),
                new BaseDataType("double","小数"),
                new BaseDataType("string","文本"),
                new BaseDataType("bool","布尔"),
                new BaseDataType("DateTime","日期")
            };

        public static ISessionFactory HbmSessionFactory { get; set; }

        public static ContentControl MinWin { get; set; }

        public static ICompany CurrentCompany { get; set; }

        public static ClientConfiguration ClientCfg
        {
            get
            {
                lock (syncClientCfgRoot)
                {
                    return clientCfg;
                }
            }
            set
            {
                lock (syncClientCfgRoot)
                {
                    clientCfg = value;
                }
            }
        }

        public static BaseDataType[] BaseDataType
        {
            get { return dts; }
        }

        public static IList<SmtpClient> SmtpClients
        {
            get
            {
                if (smtpClients == null)
                    smtpClients = MailSender.LoadSmtpClients(@"smtpclient.xml");
                return smtpClients;
            }
            set
            {
                smtpClients = value;
            }
        }

        public static ILog Log { get; set; }

        public static string GetAppPath()
        {
            return System.Environment.CurrentDirectory;
        }
    }
}
